blktap2: Further netbsd build fixes.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 24 Jun 2009 13:03:20 +0000 (14:03 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 24 Jun 2009 13:03:20 +0000 (14:03 +0100)
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
tools/blktap2/drivers/block-vhd.c
tools/blktap2/include/blk_uuid.h [new file with mode: 0644]
tools/blktap2/include/libvhd-journal.h
tools/blktap2/include/libvhd.h
tools/blktap2/include/uuid.h [deleted file]
tools/blktap2/include/vhd.h
tools/blktap2/vhd/lib/libvhd-journal.c
tools/blktap2/vhd/lib/libvhd.c
tools/blktap2/vhd/lib/vhd-util-check.c
tools/blktap2/vhd/lib/vhd-util-read.c

index 2183e287a59d2f2840898b614e03cfc1234ca37c..83db6e38ba1c4f3b5b9bf08a075e67b5f584fe95 100644 (file)
@@ -806,7 +806,7 @@ vhd_validate_parent(td_driver_t *child_driver,
        }
        */
 
-       if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
+       if (blk_uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid)) {
                DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
                        "snapshot.  Child image no longer valid.\n",
                        __func__, child->vhd.file, parent->vhd.file);
diff --git a/tools/blktap2/include/blk_uuid.h b/tools/blktap2/include/blk_uuid.h
new file mode 100644 (file)
index 0000000..8292261
--- /dev/null
@@ -0,0 +1,126 @@
+/* Copyright (c) 2008, XenSource Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of XenSource Inc. nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#ifndef __BLKTAP2_UUID_H__
+#define __BLKTAP2_UUID_H__
+
+#if defined(__linux__) || defined(__Linux__)
+
+#include <uuid/uuid.h>
+
+typedef struct {
+    uuid_t uuid;
+} blk_uuid_t;
+
+static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
+{
+       return uuid_is_null(uuid->uuid);
+}
+
+static inline void blk_uuid_generate(blk_uuid_t *uuid)
+{
+       uuid_generate(uuid->uuid);
+}
+
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+{
+       uuid_unparse(uuid->uuid, out);
+}
+
+static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
+{
+       uuid_parse(in, uuid->uuid);
+}
+
+static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
+{
+       uuid_copy(dst->uuid, src->uuid);
+}
+
+static inline void blk_uuid_clear(blk_uuid_t *uuid)
+{
+       uuid_clear(uuid->uuid);
+}
+
+static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
+{
+       return uuid_compare(uuid1->uuid, uuid2->uuid);
+}
+
+#elif defined(__NetBSD__)
+
+#include <uuid.h>
+#include <string.h>
+
+typedef uuid_t blk_uuid_t;
+
+static inline int blk_uuid_is_nil(blk_uuid_t *uuid)
+{
+       uint32_t status;
+       return uuid_is_nil((uuid_t *)uuid, &status);
+}
+
+static inline void blk_uuid_generate(blk_uuid_t *uuid)
+{
+       uint32_t status;
+       uuid_create((uuid_t *)uuid, &status);
+}
+
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+{
+       uint32_t status;
+       uuid_to_string((uuid_t *)uuid, &out, &status);
+}
+
+static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
+{
+       uint32_t status;
+       uuid_from_string(in, (uuid_t *)uuid, &status);
+}
+
+static inline void blk_uuid_copy(blk_uuid_t *dst, blk_uuid_t *src)
+{
+       memcpy((uuid_t *)dst, (uuid_t *)src, sizeof(uuid_t));
+}
+
+static inline void blk_uuid_clear(blk_uuid_t *uuid)
+{
+       memset((uuid_t *)uuid, 0, sizeof(uuid_t));
+}
+
+static inline int blk_uuid_compare(blk_uuid_t *uuid1, blk_uuid_t *uuid2)
+{
+       uint32_t status;
+       return uuid_compare((uuid_t *)uuid1, (uuid_t *)uuid2, &status);
+}
+
+#else
+
+#error "Please update blk_uuid.h for your OS"
+
+#endif
+
+#endif /* __BLKTAP2_UUID_H__ */
index 2f32ff02cad73d34503db87cff5866379d9723d4..75852523c9f0469694a8c54106836b0c78cb4b85 100644 (file)
@@ -39,7 +39,7 @@
 
 typedef struct vhd_journal_header {
        char                       cookie[8];
-       uuid_t                     uuid;
+       blk_uuid_t                 uuid;
        uint64_t                   vhd_footer_offset;
        uint32_t                   journal_data_entries;
        uint32_t                   journal_metadata_entries;
index 6d5979b1d75be97499d98dde010f687e61b57a62..71082ad8434eba7ba8ead08096a8af0bbf08062f 100644 (file)
@@ -36,7 +36,7 @@
 #include <sys/bswap.h>
 #endif
 
-#include "uuid.h"
+#include "blk_uuid.h"
 #include "vhd.h"
 
 #ifndef O_LARGEFILE
@@ -216,7 +216,7 @@ vhd_parent_locator_size(vhd_parent_locator_t *loc)
 static inline int
 vhd_parent_raw(vhd_context_t *ctx)
 {
-       return uuid_is_null(ctx->header.prt_uuid);
+       return blk_uuid_is_nil(&ctx->header.prt_uuid);
 }
 
 void libvhd_set_log_level(int);
diff --git a/tools/blktap2/include/uuid.h b/tools/blktap2/include/uuid.h
deleted file mode 100644 (file)
index e808324..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (c) 2008, XenSource Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of XenSource Inc. nor the names of its contributors
- *       may be used to endorse or promote products derived from this software
- *       without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#ifndef __BLKTAP2_UUID_H__
-#define __BLKTAP2_UUID_H__
-
-#if defined(__linux__) || defined(__Linux__)
-
-#include <uuid/uuid.h>
-
-#else
-
-#include <inttypes.h>
-#include <string.h>
-#include <uuid.h>
-
-static inline int uuid_is_null(uuid_t uuid)
-{
-    uint32_t status;
-    return uuid_is_nil(&uuid, &status);
-}
-
-static inline void uuid_generate(uuid_t uuid)
-{
-    uint32_t status;
-    uuid_create(&uuid, &status);
-}
-
-static inline void uuid_unparse(uuid_t uuid, char *out)
-{
-    uint32_t status;
-    uuid_to_string(&uuid, (char **)&out, &status);
-}
-
-static inline void uuid_copy(uuid_t dst, uuid_t src)
-{
-    memcpy(dst, src, sizeof(dst));
-}
-
-static inline void uuid_clear(uuid_t uu)
-{
-    memset(uu, 0, sizeof(uu));
-}
-
-#define uuid_compare(x,y) \
-    ({ uint32_t status; uuid_compare(&(x),&(y),&status); })
-
-#endif
-
-#endif /* __BLKTAP2_UUID_H__ */
index 25b8b29e0196c5da81b8ef45d5d5aa7b555328d3..a31aadf491e79ff457d0123916c283c4ca145eb7 100644 (file)
@@ -28,7 +28,6 @@
 #define __VHD_H__
 
 #include <inttypes.h>
-#include "uuid.h"
 
 typedef uint32_t u32;
 typedef uint64_t u64;
@@ -60,7 +59,7 @@ struct hd_ftr {
   u32    geometry;        /* Disk geometry                                */
   u32    type;            /* Disk type                                    */
   u32    checksum;        /* 1's comp sum of this struct.                 */
-  uuid_t uuid;            /* Unique disk ID, used for naming parents      */
+  blk_uuid_t uuid;        /* Unique disk ID, used for naming parents      */
   char   saved;           /* one-bit -- is this disk/VM in a saved state? */
   char   hidden;          /* tapdisk-specific field: is this vdi hidden?  */
   char   reserved[426];   /* padding                                      */
@@ -148,7 +147,7 @@ struct dd_hdr {
   u32    max_bat_size;    /* Maximum number of entries in the BAT         */
   u32    block_size;      /* Block size in bytes. Must be power of 2.     */
   u32    checksum;        /* Header checksum.  1's comp of all fields.    */
-  uuid_t prt_uuid;        /* ID of the parent disk.                       */
+  blk_uuid_t prt_uuid;    /* ID of the parent disk.                       */
   u32    prt_ts;          /* Modification time of the parent disk         */
   u32    res1;            /* Reserved.                                    */
   char   prt_name[512];   /* Parent unicode name.                         */
index 4112c9d6af587a38cb03607ea45cc9291d787621..24383ff62b299cbca0fb3016e73f37bf82b02f72 100644 (file)
@@ -237,7 +237,7 @@ vhd_journal_add_journal_header(vhd_journal_t *j)
        if (err)
                return err;
 
-       uuid_copy(j->header.uuid, vhd->footer.uuid);
+       blk_uuid_copy(&j->header.uuid, &vhd->footer.uuid);
        memcpy(j->header.cookie,
               VHD_JOURNAL_HEADER_COOKIE, sizeof(j->header.cookie));
        j->header.vhd_footer_offset = off - sizeof(vhd_footer_t);
index add9365f4201edaba6c896725a06912b8bcfb1c2..03bee720c52c5d8892d7c626da605e26a8e5f4c5 100644 (file)
@@ -1308,7 +1308,8 @@ vhd_macx_encode_location(char *name, char **out, int *outlen)
        iconv_t cd;
        int len, err;
        size_t ibl, obl;
-       char *uri, *urip, *uri_utf8, *uri_utf8p, *ret;
+       char *uri, *uri_utf8, *uri_utf8p, *ret;
+       const char *urip;
 
        err     = 0;
        ret     = NULL;
@@ -1319,7 +1320,7 @@ vhd_macx_encode_location(char *name, char **out, int *outlen)
        ibl     = len;
        obl     = len;
 
-       uri = urip = malloc(ibl + 1);
+       urip = uri = malloc(ibl + 1);
        uri_utf8 = uri_utf8p = malloc(obl);
 
        if (!uri || !uri_utf8)
@@ -1333,7 +1334,11 @@ vhd_macx_encode_location(char *name, char **out, int *outlen)
 
        snprintf(uri, ibl+1, "file://%s", name);
 
-       if (iconv(cd, &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
+       if (iconv(cd,
+#if defined(__linux__) || (__Linux__)
+           (char **)
+#endif
+           &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
            ibl || obl) {
                err = (errno ? -errno : -EIO);
                goto out;
@@ -1364,7 +1369,8 @@ vhd_w2u_encode_location(char *name, char **out, int *outlen)
        iconv_t cd;
        int len, err;
        size_t ibl, obl;
-       char *uri, *urip, *uri_utf16, *uri_utf16p, *tmp, *ret;
+       char *uri, *uri_utf16, *uri_utf16p, *tmp, *ret;
+       const char *urip;
 
        err     = 0;
        ret     = NULL;
@@ -1418,7 +1424,11 @@ vhd_w2u_encode_location(char *name, char **out, int *outlen)
                goto out;
        }
 
-       if (iconv(cd, &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
+       if (iconv(cd,
+#if defined(__linux__) || (__Linux__)
+           (char **)
+#endif
+           &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
            ibl || obl) {
                err = (errno ? -errno : -EIO);
                goto out;
@@ -1459,7 +1469,11 @@ vhd_macx_decode_location(const char *in, char *out, int len)
        if (cd == (iconv_t)-1) 
                return NULL;
 
-       if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+               (char **)
+#endif
+               &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
                return NULL;
 
        iconv_close(cd);
@@ -1487,7 +1501,11 @@ vhd_w2u_decode_location(const char *in, char *out, int len, char *utf_type)
        if (cd == (iconv_t)-1) 
                return NULL;
 
-       if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+               (char **)
+#endif
+               &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
                return NULL;
 
        iconv_close(cd);
@@ -2435,7 +2453,7 @@ vhd_initialize_footer(vhd_context_t *ctx, int type, uint64_t size)
        ctx->footer.saved        = 0;
        ctx->footer.data_offset  = 0xFFFFFFFFFFFFFFFF;
        strcpy(ctx->footer.crtr_app, "tap");
-       uuid_generate(ctx->footer.uuid);
+       blk_uuid_generate(&ctx->footer.uuid);
 }
 
 static int
@@ -2479,7 +2497,11 @@ vhd_initialize_header_parent_name(vhd_context_t *ctx, const char *parent_path)
 
        memset(dst, 0, obl);
 
-       if (iconv(cd, (char **)&pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+               (char **)
+#endif
+               &pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
                err = (errno ? -errno : -EINVAL);
 
 out:
@@ -2546,7 +2568,7 @@ vhd_initialize_header(vhd_context_t *ctx, const char *parent_path,
                        return err;
 
                ctx->header.prt_ts = vhd_time(stats.st_mtime);
-               uuid_copy(ctx->header.prt_uuid, parent.footer.uuid);
+               blk_uuid_copy(&ctx->header.prt_uuid, &parent.footer.uuid);
                if (!size)
                        size = parent.footer.curr_size;
                vhd_close(&parent);
@@ -2628,7 +2650,7 @@ vhd_change_parent(vhd_context_t *child, char *parent_path, int raw)
        }
 
        if (raw) {
-               uuid_clear(child->header.prt_uuid);
+               blk_uuid_clear(&child->header.prt_uuid);
        } else {
                err = vhd_open(&parent, ppath, VHD_OPEN_RDONLY);
                if (err) {
@@ -2636,7 +2658,7 @@ vhd_change_parent(vhd_context_t *child, char *parent_path, int raw)
                               ppath, child->file, err);
                        goto out;
                }
-               uuid_copy(child->header.prt_uuid, parent.footer.uuid);
+               blk_uuid_copy(&child->header.prt_uuid, &parent.footer.uuid);
                vhd_close(&parent);
        }
 
@@ -2695,7 +2717,7 @@ vhd_create_batmap(vhd_context_t *ctx)
        header    = &ctx->batmap.header;
 
        memset(header, 0, sizeof(vhd_batmap_header_t));
-       memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(*header->cookie));
+       memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(header->cookie));
 
        err = vhd_batmap_header_offset(ctx, &off);
        if (err)
index 9dbd9e1941cd95d19af1bf32a4b40d0b634fb870..b6bb1b7c52bb924e70a20ac7a4b589c0e6f86897 100644 (file)
@@ -218,7 +218,7 @@ vhd_util_check_validate_differencing_header(vhd_context_t *vhd)
                if (vhd_util_check_zeros(header->loc, sizeof(header->loc)))
                        return "invalid non-null parent locators";
 
-               if (!uuid_is_null(header->prt_uuid))
+               if (!blk_uuid_is_nil(&header->prt_uuid))
                        return "invalid non-null parent uuid";
 
                if (header->prt_ts)
@@ -320,7 +320,7 @@ vhd_util_check_validate_parent(vhd_context_t *vhd, const char *ppath)
                                VHD_OPEN_RDONLY | VHD_OPEN_IGNORE_DISABLED))
                return "error opening parent";
 
-       if (uuid_compare(vhd->header.prt_uuid, parent.footer.uuid)) {
+       if (blk_uuid_compare(&vhd->header.prt_uuid, &parent.footer.uuid)) {
                msg = "invalid parent uuid";
                goto out;
        }
index a462fdc4df8225d21a2a3d3d22bb3a92ec75cc22..0afb3dcceb3bf34287d265773a8ca353d898cea5 100644 (file)
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd_header_t *h, int hex)
               (err ? "failed to read name" : name));
        free(name);
 
-       uuid_unparse(h->prt_uuid, uuid);
+       blk_uuid_to_string(&h->prt_uuid, uuid);
        printf("Parent UUID         : %s\n", uuid);
     
        vhd_time_to_string(h->prt_ts, time_str);
@@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int hex)
        printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
                f->checksum == cksm ? "Good!" : "Bad!");
 
-       uuid_unparse(f->uuid, uuid);
+       blk_uuid_to_string(&f->uuid, uuid);
        printf("UUID                : %s\n", uuid);
 
        printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");